package com.example.sinteractactivity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import static android.R.attr.data;

public class Main2Activity extends AppCompatActivity {

    private EditText edit2;
    private TextView text2;
    private Button but2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        edit2 = (EditText)findViewById(R.id.edit2);
        text2 = (TextView)findViewById(R.id.text2);
        but2 = (Button)findViewById(R.id.but2);

        Intent intent = getIntent();
        text2.append("小张"+":"+intent.getStringExtra("msg"));
        but2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(Main2Activity.this,MainActivity.class);
                //Bundle bundle1 = new Bundle();
                //bundle1.putString("msg1",text2.getText().toString());
                //bundle1.putString("msg1","小王："+edit2.getText().toString());
                //intent1.putExtras(bundle1);
                //startActivityForResult(intent1,1);
                intent1.putExtra("msg1",edit2.getText().toString());
                setResult(RESULT_OK,intent1);
                finish();
            }
        });



    }
}
